home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / FLDPAK.ZIP / FPDEMO1.FRM < prev    next >
Text File  |  1994-02-02  |  10KB  |  268 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Invoice Browser (FieldPack demo program 1)"
  5.    ClientHeight    =   2505
  6.    ClientLeft      =   2220
  7.    ClientTop       =   1995
  8.    ClientWidth     =   5460
  9.    Height          =   3195
  10.    Left            =   2160
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2505
  13.    ScaleWidth      =   5460
  14.    Top             =   1365
  15.    Width           =   5580
  16.    Begin ListBox lstInvoices 
  17.       FontBold        =   -1  'True
  18.       FontItalic      =   0   'False
  19.       FontName        =   "Courier"
  20.       FontSize        =   9.75
  21.       FontStrikethru  =   0   'False
  22.       FontUnderline   =   0   'False
  23.       Height          =   1005
  24.       Left            =   810
  25.       Sorted          =   -1  'True
  26.       TabIndex        =   2
  27.       Top             =   1080
  28.       Width           =   4035
  29.    End
  30.    Begin TextBox txt_hidden_NumberOfInvoices 
  31.       BackColor       =   &H00808080&
  32.       DataField       =   "NumberOfInvoices"
  33.       DataSource      =   "Data1"
  34.       Height          =   285
  35.       Left            =   4440
  36.       TabIndex        =   0
  37.       Top             =   0
  38.       Visible         =   0   'False
  39.       Width           =   495
  40.    End
  41.    Begin Data Data1 
  42.       BackColor       =   &H0000FF00&
  43.       Caption         =   "Customer Name"
  44.       Connect         =   ""
  45.       DatabaseName    =   "c:\FPDEMO1.MDB"
  46.       Exclusive       =   0   'False
  47.       ForeColor       =   &H00000000&
  48.       Height          =   270
  49.       Left            =   1440
  50.       Options         =   0
  51.       ReadOnly        =   0   'False
  52.       RecordSource    =   "InvoicesByCustomer"
  53.       Top             =   240
  54.       Width           =   2565
  55.    End
  56.    Begin Label lblCountDisplay 
  57.       BackColor       =   &H00C0C0C0&
  58.       Caption         =   "3"
  59.       FontBold        =   -1  'True
  60.       FontItalic      =   0   'False
  61.       FontName        =   "MS Sans Serif"
  62.       FontSize        =   12
  63.       FontStrikethru  =   0   'False
  64.       FontUnderline   =   0   'False
  65.       ForeColor       =   &H000000FF&
  66.       Height          =   255
  67.       Left            =   2850
  68.       TabIndex        =   6
  69.       Top             =   2130
  70.       Width           =   195
  71.    End
  72.    Begin Label Label3 
  73.       BackColor       =   &H00C0C0C0&
  74.       Caption         =   "open invoices."
  75.       FontBold        =   -1  'True
  76.       FontItalic      =   -1  'True
  77.       FontName        =   "MS Sans Serif"
  78.       FontSize        =   8.25
  79.       FontStrikethru  =   0   'False
  80.       FontUnderline   =   0   'False
  81.       Height          =   255
  82.       Left            =   3090
  83.       TabIndex        =   5
  84.       Top             =   2160
  85.       Width           =   1695
  86.    End
  87.    Begin Label Label1 
  88.       BackColor       =   &H00C0C0C0&
  89.       Caption         =   "This customer has"
  90.       FontBold        =   -1  'True
  91.       FontItalic      =   -1  'True
  92.       FontName        =   "MS Sans Serif"
  93.       FontSize        =   8.25
  94.       FontStrikethru  =   0   'False
  95.       FontUnderline   =   0   'False
  96.       Height          =   255
  97.       Left            =   1080
  98.       TabIndex        =   4
  99.       Top             =   2160
  100.       Width           =   1695
  101.    End
  102.    Begin Label lblCustomerName 
  103.       BorderStyle     =   1  'Fixed Single
  104.       DataField       =   "CustomerName"
  105.       DataSource      =   "Data1"
  106.       FontBold        =   -1  'True
  107.       FontItalic      =   0   'False
  108.       FontName        =   "Courier"
  109.       FontSize        =   9.75
  110.       FontStrikethru  =   0   'False
  111.       FontUnderline   =   0   'False
  112.       Height          =   255
  113.       Left            =   2010
  114.       TabIndex        =   3
  115.       Top             =   480
  116.       Width           =   1425
  117.    End
  118.    Begin Label Label2 
  119.       BackColor       =   &H00C0C0C0&
  120.       Caption         =   "Invoice Date           Amount          Terms"
  121.       Height          =   255
  122.       Left            =   960
  123.       TabIndex        =   1
  124.       Top             =   840
  125.       Width           =   3615
  126.    End
  127.    Begin Menu mnuFile 
  128.       Caption         =   "&File"
  129.       Begin Menu mnuExit 
  130.          Caption         =   "E&xit"
  131.       End
  132.    End
  133.    Begin Menu mnuExplain 
  134.       Caption         =   "&Explain"
  135.    End
  136. End
  137. Option Explicit
  138.  
  139. 'Program FPDEMO1
  140. 'October 1993
  141. 'By: Sam Cohen
  142. 'Software Source
  143. '42808 Christy St., Ste. 222
  144. 'Fremont, CA  94538  USA
  145. 'Tel +1(510)623-7854   Fax +1(510)651-6039
  146.  
  147. 'Most of the commentary in this program is in the single
  148. 'subroutine "LoadListBox."   (The only other code at all
  149. 'is in Form_Load, lblCustomerName_Change, mnuExplain, and
  150. 'mnuExit.)
  151.  
  152. Sub Form_Load ()
  153.  
  154.     Dim rc As Integer
  155.     MsgBox "This program expects to find the file FPDEMO1.MDB in the root directory of your C: drive.  Please wait while the VB3 MS-Access engine opens this file.", 64, "FieldPack Demo Program 1 -- Software Source"
  156.     rc = FP_Password("Sorry, you'll have to register to get a proper password.")
  157.  
  158. End Sub
  159.  
  160. Sub lblCustomerName_Change ()
  161.  
  162.     'A change to this data-linked control means that
  163.     'we need to reload the list box, since the user has
  164.     'selected a new record.  Each record represents a
  165.     'different customer.  There are three fields in each
  166.     'record:  customer name (which is automatically dis-
  167.     'played in the caption of this data-linked label
  168.     'control); the number of "packed" invoices; and a
  169.     'SuperString (physically stored as a Memo field in
  170.     'the Access database file) containing the packed
  171.     'invoices.  We use a SuperString function to unpack
  172.     'the invoice information and display it in the list
  173.     'box, one invoice per line.
  174.  
  175.     LoadListBox
  176.  
  177. End Sub
  178.  
  179. Sub LoadListBox ()
  180.  
  181.     Dim SS_Format As String
  182.     Dim NumberOfInvoices As Integer
  183.     Dim InvoiceCount As String
  184.     Dim SuperString As String
  185.     Dim Invoice As String
  186.     Dim InvoiceDate As String
  187.     Dim Amount As String
  188.     Dim Terms As String
  189.     Dim ListBoxLine As String
  190.     Dim LoopCounter As Integer
  191.     Dim rc As Integer
  192.  
  193.     lstInvoices.Clear       'Just to be neat, let's first clear out the list box.
  194.     
  195.     SuperString = Data1.Recordset.Fields("Invoices").Value   'Reads the SuperString out of the Access database.
  196.  
  197.     InvoiceCount = US_StripOut((txt_hidden_NumberOfInvoices.Text), " ")   'Note data-linked text box.
  198.     
  199.     SS_Format = "A" + InvoiceCount + "$"
  200.         'The above line of code builds the "Format Description String" we need to supply with
  201.         'any call to a SuperString function (such as the SS_FetchItem call you see below).
  202.         'In this demo, we use a simple SuperString format consisting of only one "piece,"
  203.         'an array of variable length strings.  The number of array elements varies from
  204.         'instance to instance (i.e., from record to record).  Each array element (variable-
  205.         'length string) contains information about a single invoice.  So, if customer XYZ
  206.         'has 6 invoices outstanding, the SuperString for that record contains a 6-element
  207.         'array of variable-length strings, and that SuperString is described with the
  208.         'format string "A6$".
  209.  
  210.  
  211.     lblCountDisplay.Caption = InvoiceCount   'Big red digits.
  212.     
  213.     NumberOfInvoices = Val(InvoiceCount)
  214.  
  215.     For LoopCounter = 1 To NumberOfInvoices
  216.  
  217.         rc = SS_FetchItem(SuperString, SS_Format, LoopCounter, "$", Invoice)
  218.             'The above function call extracts an "item" (in this case, a string containing
  219.             'information about a single invoice) from a SuperString.
  220.  
  221.         If rc <> 0 Then MsgBox "SS error " + Str$(rc)
  222.  
  223.         'Now, we're going to switch gears and demonstrate use of our Delimited Substring (DS_)
  224.         'capabilities (in a very minor way); the DS_GetField calls pick out variable-length
  225.         'substrings ("fields") delimited, in this case, by the "|" character:
  226.  
  227.         InvoiceDate = DS_GetField(Invoice, "|", 1)
  228.         Amount = DS_GetField(Invoice, "|", 2)
  229.         Terms = DS_GetField(Invoice, "|", 3)
  230.  
  231.         'Finally, just for completeness, th